﻿using RotovapPlatform.Domain.Business.Machine.Enums;
using RotovapPlatform.Domain.Common;
using System;
using System.Threading.Tasks;

namespace RotovapPlatform.Domain.Services.Devices
{
	/// <summary>
	/// 设备领域服务接口
	/// 负责设备模式切换和状态管理的领域逻辑
	/// </summary>
	public interface IDeviceDomainService
	{
		/// <summary>
		/// 获取当前设备模式
		/// </summary>
		/// <returns>当前设备模式</returns>
		Task<DeviceEnums.DeviceMode> GetCurrentDeviceModeAsync();

		/// <summary>
		/// 设置设备模式
		/// </summary>
		/// <param name="mode">目标设备模式</param>
		/// <returns>操作结果</returns>
		Task<OperationResult> SetDeviceModeAsync(DeviceEnums.DeviceMode mode);

		/// <summary>
		/// 获取设备状态
		/// </summary>
		/// <returns>当前设备状态</returns>
		Task<DeviceEnums.DeviceStatus> GetDeviceStatusAsync();

		/// <summary>
		/// 获取可用的设备模式列表
		/// </summary>
		/// <returns>可用的设备模式列表</returns>
		Task<DeviceEnums.DeviceMode[]> GetAvailableModesAsync();

		/// <summary>
		/// 检查指定模式是否可用
		/// </summary>
		/// <param name="mode">要检查的模式</param>
		/// <returns>如果模式可用则返回true，否则返回false</returns>
		Task<bool> IsModeAvailableAsync(DeviceEnums.DeviceMode mode);

		/// <summary>
		/// 设备模式变更事件
		/// </summary>
		event EventHandler<DeviceModeChangedEventArgs> DeviceModeChanged;

		/// <summary>
		/// 设备状态变更事件
		/// </summary>
		event EventHandler<DeviceStatusChangedEventArgs> DeviceStatusChanged;

		/// <summary>
		/// 开始监控设备状态
		/// </summary>
		Task StartMonitoringAsync();

		/// <summary>
		/// 停止监控设备状态
		/// </summary>
		Task StopMonitoringAsync();

		/// <summary>
		/// 更新设备状态
		/// </summary>
		/// <param name="status">设备状态</param>
		void UpdateDeviceStatus(DeviceEnums.DeviceStatus status);
	}

	/// <summary>
	/// 设备模式变更事件参数
	/// </summary>
	public class DeviceModeChangedEventArgs : EventArgs
	{
		/// <summary>
		/// 设备模式
		/// </summary>
		public DeviceEnums.DeviceMode Mode { get; }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="mode">设备模式</param>
		public DeviceModeChangedEventArgs(DeviceEnums.DeviceMode mode)
		{
			Mode = mode;
		}
	}

	/// <summary>
	/// 设备状态变更事件参数
	/// </summary>
	public class DeviceStatusChangedEventArgs : EventArgs
	{
		/// <summary>
		/// 设备状态
		/// </summary>
		public DeviceEnums.DeviceStatus Status { get; }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="status">设备状态</param>
		public DeviceStatusChangedEventArgs(DeviceEnums.DeviceStatus status)
		{
			Status = status;
		}
	}
}